$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        readForm:null,
        currentFrame:null,
        init:function () {
            this.form = new xhForm($('#xh_form')).parse();
            this.readForm = new xhForm($('#readForm')).parse();
            if (info) {
                this.form.fill(info);
                this.readForm.fill(info);
            }
            this.form.bindRequired($('#save'));
            this.listener();
            if (info && info['iState'] == 5) {
                $('[href="#style3Tab7"]').click();
            }
        },
        listener:function () {
            var $this = this;
            
            $('#save').click(function () {
                $this.funObj().save();
            });
            
            $('.tab-bar a').click(function () {
                $this.funObj().tabClick($(this));
            })
        },
        funObj:function () {
            var $this = this;
            return {
                save:function () {
                    var phoneReg = /^1[0-9]{10}$/;
                    if(!phoneReg.test($('[name=sSelfPhone]').val())) {
                        window.top.xhTop.showError('错误', '手机号格式不匹配');
                        return false;
                    }
                    $this.form.submit('hrm/resource/saveSource',{},function (res) {
                        // if (res.staffId && !info) {
                        //     $('#title',parent.document).contents()[0]['data'] = $('[name=sStaffName]').val();
                        //     location.href = baseUrl+ 'hrm/resource/sourceTab?staffId='+res.staffId;
                        // }
                        window.top.xhTop.showSuccess(res.msg);
                    })
                },
                saveEmployInfo:function () {
                    $this.readForm.submit('hrm/resource/saveSource',{},function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                    })
                },
                tabClick:function (target) {
                    var $id = target.attr('href');
                    var frame = $($id).find('iframe');
                    if (frame.length > 0) {
                        $this.currentFrame = frame;
                        var name = frame.attr('name');
                        var src = frame.attr('src');
                        if (!src) {
                            if (!sourceId) {
                                sendErrorMsg('错误', '缺少id');
                                return false;
                            }
                            if (name == 'leanExperience') {
                                frame.attr('src', baseUrl + 'hrm/resource/experience/lean?sourceId=' + sourceId);
                            } else if (name == 'workExperience') {
                                frame.attr('src', baseUrl + 'hrm/resource/experience/work?sourceId=' + sourceId);
                            } else if (name == 'itemExperience') {
                                frame.attr('src', baseUrl + 'hrm/resource/experience/item?sourceId=' + sourceId);
                            } else if (name == 'family') {
                                frame.attr('src', baseUrl + 'hrm/resource/family?sourceId=' + sourceId);
                            } else if (name == 'employ') {
                                frame.attr('src', baseUrl + 'hrm/resource/employ?sourceId=' + sourceId);
                            } else {
                                return false;
                            }
                        }
                    }
                }
            }
        }
    }
};